<?php
/**
 * 用户相关接口请求参数验证器
 * Created by PhpStorm.
 * User: LRChang
 * Date: 2018/06/05
 * Time: 10:10
 * Mail: hjklrchang@qq.com
 */

namespace app\adminapi\validate;

use app\base\validate\BaseValidate;

class UserValidate extends BaseValidate
{
    protected $rule = [
        'page' => 'isPositiveInt',
        'pagenum' => 'isPositiveInt',
        'where_json' => 'isWhereJson',

        'username' => 'require|max:50',
        'password' => 'require|max:50',
        'mobile' => 'require|isMobile',
        'code' => 'require|integer|length:6',

        'user_id'=>'require|isPositiveInt',
        'area_id'=>'isPositiveInt',
        'role_id'=>'require|checkIDs',
        'state'=>'require|in:1,9',
        'company_id'=> 'require|integer|>=:0',

        'user_ids' => 'require|checkIDs',
    ];

    // 默认值
    protected $default = [
        'page' => 1,
        'pagenum' => 20,
        'where_json' => '',
        'fields' => '*',

        'area_id' => 4
    ];

    protected $message = [
        'username.require' => '用户名不能为空',
        'password.require' => '密码不能为空',
        'mobile.require' => '手机号不能为空',
        'mobile.isMobile' => '手机号格式不正确',
        'code.length' => '短信验证码为6位数字'
    ];

    protected $scene = [
        'list' => ['page' ,'pagenum', 'fields', 'where_json'],
        'add' => [
          'username',
          'password',
          'mobile',
          'area_id',
          'role_id',
          'state',
          'company_id',
        ],
        'edit' => [
            'user_id',
            'username',
            'password' => 'max:50',
            'mobile',
            'area_id',
            'role_id',
            'state',
            'company_id',
        ],
        'delete' => ['user_ids'],
        'login_by_name' => ['username', 'password'],
        'login_by_sms' => ['mobile', 'code'],
        'get_sms_code' => ['mobile'],
    ];
}